﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using TheDrinksApp.Database;
using TheDrinksApp.Models;
using TheDrinksApp.Screen.CurrentOrder.TableViewCell;
using System.Collections.ObjectModel;
namespace TheDrinksApp.Screen.CurrentOrder
{
    public partial class CurrentOrderScreen : UserControl
    {
        MainPage parrent;
        public CurrentOrderScreen(MainPage _parrent )
        {
            InitializeComponent();
            parrent = _parrent;            
        }
        public void DeleteAtIndex(int index)
        {
            Util.currentOrders.RemoveAt(index);
            
            UserControl_Loaded_1(null, null);
        }
        public void GoToDetail(CurrentOrderDAO order)
        {
            Util.nowEditting = order;
            Util.preDetailPage = PAGE.CURRENT_ORDER;
            parrent.ShowPage(PAGE.ORDER_ITEM_DETAIL);

        }
        private void UserControl_Loaded_1(object sender, RoutedEventArgs e)
        {
            GlobalVariable.mainPage.SetCurrentNumber();
            listResult.Items.Clear();
            for (int i = 0; i < Util.currentOrders.Count; i++)
            {
                listResult.Items.Add(new CurrentOrderTableViewCell(Util.currentOrders[i], this, i));
            }
        }

        private void Image_Tap_3(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (Util.currentOrders.Count == 0)
                return;
            Util.goFromRecentOrCurrent = 0;
            parrent.ShowPage(PAGE.SUMARY_SCREEN);
        }

        private void Image_Tap_4(object sender, System.Windows.Input.GestureEventArgs e)
        {
            parrent.ShowPage(PAGE.CHOOSE_CATEGORY);
        }

        public void hideAllDeleteButton()
        {
            foreach (var item in listResult.Items)
            {
                ((CurrentOrderTableViewCell)item).hideDeleteButton();
            }
        }
    }
}
